class Music extends eui.Component {
    private _bgMusic: egret.Sound;
    private _countMusic: egret.Sound;
    private _gameOverMusic: egret.Sound;

    private _bgChannel: egret.SoundChannel;
    private _countChannel: egret.SoundChannel;
    private _gameOverChannel: egret.SoundChannel;

    public userId: number = 0;
    public score: number = 0;

    constructor() {
        super()
        this._bgMusic = RES.getRes('backgroundMusic_mp3');
        this._countMusic = RES.getRes('countDown_mp3');
        this._gameOverMusic = RES.getRes('gameOver_mp3');


    }
    // 播放背景音乐
    public playBg() {
        // var sound: egret.Sound = RES.getRes('countDown_mp3');
        // this._bgMusic = RES.getRes('backgroundMusic_mp3');
        this._bgChannel = this._bgMusic.play();
    }
    // 停止背景音乐
    public stopBg() {
        this._bgChannel.stop();
    }
    // 播放倒计时音乐
    public playCount() {
        // this._countMusic = RES.getRes('countDown_mp3');
        this._countChannel = this._countMusic.play();
    }
    // 停止倒计时音乐
    public stopCount() {
        this._countChannel.stop();
    }
    // 播放游戏结束音乐
    public playGameOver() {
        // this._gamueUI = new GameUI();
        // this._gameOverMusic = RES.getRes('gameover_mp3');
        this._gameOverChannel = this._gameOverMusic.play(0, 1);

        this._gameOverChannel.addEventListener(egret.Event.SOUND_COMPLETE, this.onSoundComplete, this)

    }
    private onSoundComplete() {

        // this._gamueUI.showOver();

        const url = `http://zzyunxun.com:8093/lsk/mobile/game/gameOver?userID=${this.userId}&endLevel=${this.score}`;

        window.location.replace(url)
    }
    // 停止游戏结束音乐
    public stopGameOver() {
        this._gameOverChannel.stop();
    }
}